<?php
#约会表
class AppointmentModel extends PdoModel {
    protected $_name = 'appointment';

    function __construct(){
        parent::__construct();
    }

    #添加
    function addData($data){
        if(empty($data)){
            return false;
        }
        return $this->insert($data);
    }

    #删除
    function deleteData($id = 0){
        if(empty($id)){
            return false;
        }
        $row = $this->find("id = {$id}");
        if (empty($row)) {
            return false;
        }
        return $this->delete("id = {$id}");
    }

    #更新
    function updateDataById($data,$id){
        return $this->update($data,"id = {$id}");
    }


    #更新
    function updateDataByDateId($data,$date_id){
        return $this->update($data,"date_id = {$date_id}");
    }


    function getDataById($id){
        if(empty($id)){
            return array();
        }

        $sql = " select * from {$this->_name} where id={$id} limit 1";
        $result = $this->fetchRow($sql);

        return $result;
    }


    #查询所有这次参加约会的人
    function getDataByDateId($date_id){
        if(empty($date_id)){
            return array();
        }

        $sql = " select * from {$this->_name} where date_id={$date_id}";
        $result = $this->fetchAll($sql);

        return $result;
    }

    function getDataByUid($uid){
        if(empty($uid)){
            return array();
        }

        $sql = " select * from {$this->_name} where uid={$uid} and status=1 limit 1";
        $result = $this->fetchRow($sql);

        return $result;
    }


}
